<template>
    <div class="jsbosContractSelect">
        <el-input ref="reference" v-model="innerValue" type="text" :placeholder="currentPlaceholder" :disabled="disabled"
            readonly>
            <template slot="append">
                <el-button @click="clickHandle" style="min-width: 100px;" :disabled="disabled">
                    选择
                </el-button>
            </template>
        </el-input>
        <procurePool v-if="ContractVisible" ref="procurePool" @refreshDataList="getContractObj" :source="sourceType" />
    </div>
</template>

<script>
import request from "@/utils/request";

import procurePool from "./procurePool/index.vue";
export default {
    name: "jsbosContractSelect",
    components: {
        procurePool
    },
    props: {
        value: {
            type: [String, Array],
            default: ""
        },
        currentPlaceholder: {
            type: String,
            default: "请选择合同"
        },
        sourceType: {
            type: String,
            default: ""
        },
        disabled: {
            type: Boolean,
            default: false
        },
        isProcure: {
            type: Boolean,
            default: false
        },
        disabled:{
            type:Boolean,
            default:true
        }
    },
    data() {
        return {
            innerValue: '',
            ContractVisible: false,
        };
    },
    watch: {
        value(val) {
            this.setDefault();
        },
    },
    computed: {},
    created() { },
    mounted() {
        this.setDefault();
    },
    beforeDestroy() {

    },
    methods: {
        setDefault() {
            console.log('初始化', this.value);
            // 生效了
            if (this.value) {
                this.$emit('load', true);
                if (this.isProcure) {
                    request({
                        url: `/api/contract/RkProcureChange/` + this.value,
                        method: "GET",
                    }).then((res) => {
                        // console.log('resssssssssssssssss', res.data)
                        this.$emit('getContractData', res.data);
                        this.innerValue = res.data.procureName;
                        this.$emit('load', false);
                    }).catch(err => this.$emit('load', false));
                } else {
                    request({
                        url: `/api/contract/RkContractProcure/` + this.value,
                        method: "GET",
                    }).then((res) => {
                        // console.log('resssssssssssssssss', res.data)
                        this.$emit('getContractData', res.data);
                        this.innerValue = res.data.procureName;
                        this.$emit('load', false);
                    }).catch(err => this.$emit('load', false));
                }

            }
        },
        clickHandle() {
            this.ContractVisible = true;
            this.$nextTick(() => {
                this.$refs.procurePool.init('procure', 0);
            });
        },
        getContractObj(list) {
            this.emitValue(list.id);
        },
        emitValue(val) {
            console.log('获取到参数', val)
            this.$emit('input', val);
            this.$emit('setInit', val);
        }
    }
};
</script>